package com.gopay.cashier.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 页面监控
 * @author ddh02
 * @PageMonitorController
 * @2017/4/19 17:07  www.gopay.com.cn Inc.All rights reserved.
 */

@Controller
@RequestMapping("/pageMonitor")
public class PageMonitorController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(PageMonitorController.class);

    @ResponseBody
    @RequestMapping("refresh")
    public void refresh(HttpServletRequest request, HttpServletResponse response) {

        try {
            printHeader();
            String orderId = request.getParameter("orderId");

            logger.info("页面刷新动作：orderId=" + orderId);

            //String url = request.getRequestURL().toString();
        } catch (Exception e) {
            logger.error("" + e);
        }
    }


    @ResponseBody
    @RequestMapping("loader")
    public void loader(
            String orderId, Long startTime, Long loadTime, Long endTime,
            HttpServletRequest request, HttpServletResponse response) {

        try {
            printHeader();
            /*logger.info("页面动作：orderId={},startTime={},loadTime={},endTime={}"
            , new Object[]{orderId, startTime, loadTime, endTime});*/

            if (startTime != null && loadTime != null && endTime != null) {
                logger.info("页面动作：orderId={},startTime={},loadTime={},endTime={},进入到加载时间={}，加载到提交时间={}",
                        new Object[]{orderId, startTime, loadTime, endTime, loadTime - startTime, endTime - loadTime});
            } else {
                logger.info("页面动作：orderId={},startTime={},loadTime={},endTime={}"
                        , new Object[]{orderId, startTime, loadTime, endTime});
            }

            //String url = request.getRequestURL().toString();
        } catch (Exception e) {
            logger.error("" + e);
        }
    }

}
